package com.xiaoyu.base.entity;

import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import androidx.annotation.NonNull;

import java.util.Objects;

@Entity(tableName = "area", indices = {@Index(value = {"name", "superiorName", "level"}, unique = true)})
public class AreaEntity {

    @PrimaryKey
    private long id;
    @NonNull
    private String name;
    @NonNull
    private String superiorName;
    private int level;

    public AreaEntity() {
        name = "";
        superiorName = "";
        level = -1;
    }

    @Ignore
    public AreaEntity(long id, @NonNull String name, @NonNull String superiorName, int level) {
        this.id = id;
        this.name = name;
        this.superiorName = superiorName;
        this.level = level;
    }

    @NonNull
    public String getName() {
        return name;
    }

    public void setName(@NonNull String name) {
        this.name = name;
    }

    @NonNull
    public String getSuperiorName() {
        return superiorName;
    }

    public void setSuperiorName(@NonNull String superiorName) {
        this.superiorName = superiorName;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AreaEntity other = (AreaEntity) o;
        if (!name.equals(other.name)) {
            return false;
        }
        if (!superiorName.equals(other.superiorName)) {
            return false;
        }
        if (level != other.level) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, superiorName, level);
    }

    @Override
    public String toString() {
        return "AreaEntity{" +
                "name='" + name + '\'' +
                ", superiorName='" + superiorName + '\'' +
                ", level=" + level +
                '}';
    }
}
